#include "GMReturnPing.h"
#include "Factory.h"
#include "Timer.h"
#include "MessageQueue.h"

#include <iostream>

GMReturnPing::GMReturnPing()
{

}

void GMReturnPing::Execute()
{

}

bool GMReturnPing::Read(SocketMessage* sm)
{
	int tempTS = 0;
	sm->ReadInt(&tempTS);
	m_timeStamp = (unsigned int)tempTS;
	//SDL_Delay(1500);
	//TheTimer::Instance()->UpdateTime();
	//float curTime = TheTimer::Instance()->GetTime();
	//float ts = m_timeStamp;
	//curTime -= ts;
	//SDL_Delay(1000);
	m_latency = TheTimer::Instance()->GetTimeMS() - m_timeStamp;
	std::cout << "latency in ms: " << m_latency << std::endl;
	TheMsgQueue::Instance()->AddLagTime(m_latency);

	return true;
}

void GMReturnPing::Write(SocketMessage* sm)
{
	sm->WriteString("GMReturnPing");
	sm->WriteInt(m_timeStamp);
}